<?php
require 'config.php';

$user_id = $_REQUEST['user_id'];
$orderId = $_REQUEST['orderId'];
$status = $_REQUEST['status'];
$sql = "update " . $oto . "_orders set orderStatus='{$status}' where userId='{$user_id}' and orderId='{$orderId}'";
$result2 = $db->query($sql);
if ($status == '8' || $status == 8) {
    $time = date('Y-m-d H:i:s');
    //$sql = "update " . $oto . "_orders set confirmTime='{$time}' where userId='{$user_id}' and orderId='{$orderId}'";
    $sql = "update " . $oto . "_orders set signTime='{$time}',isConfirm='1' where userId='{$user_id}' and orderId='{$orderId}'";
    $result = $db->query($sql);
    $sql = "SELECT shopId,needPay,commission,orderScore,orderNo,deliverType FROM " . $oto . "_orders where orderId='{$orderId}' ";
    $result = $db->query($sql);
    while ($row = $result->fetch_assoc()) {
        $orders[] = $row; //将取得的所有数据赋值给person_info数组
    }
    $shopId = $orders[0]['shopId'];
    if (isset($orders)) {
        $jia = $orders[0]['needPay'] - $orders[0]['commission'];
    } else {
        $jia = 0;
    }
    $sql = "update " . $oto . "_shops set bizMoney=bizMoney+'$jia' where shopId='{$shopId}'";
    $result = $db->query($sql);

    $sql = "SELECT * FROM " . $oto . "_users where userId='{$user_id}'";
    $result = $db->query($sql);
    while ($row = $result->fetch_assoc()) {
        $users[] = $row; //将取得的所有数据赋值给person_info数组
    }
    $sql = "SELECT * FROM " . $oto . "_orders where orderId='{$orderId}'";
    $result = $db->query($sql);
    while ($row = $result->fetch_assoc()) {
        $orders[] = $row; //将取得的所有数据赋值给person_info数组
    }
    $orderScore = $orders[0]['orderScore'];
    $order_no = $orders[0]['orderNo'];
    $z_user_score = $users[0]['userScore'] + $orderScore;
    $time = time();

    $sql = "update " . $oto . "_users set userScore=userScore+'$orderScore' where userId='{$user_id}'";
    $result = $db->query($sql);
    $sql = "INSERT INTO " . $oto . "_score_record (`userid`,`orderNo`,`score`,`totalscore`,`time`,`IncDec`,`type`) VALUES ('$user_id','$order_no','$orderScore','$z_user_score','$time','1','1')";
    $result = $db->query($sql);
    //if ($orders[0]['deliverType'] == 1) {
        changePtOrder($orderId, 1);
    //}
}
if ($result2) {
    $data[0]['pan'] = 'true';
} else {
    $data[0]['pan'] = 'false';
}

echo json_encode($data);
